home *** CD-ROM | disk | FTP | other *** search
/ CYBER.XPO.95 / CYBER.XPO.95 (Arsenal Computer).ISO / popreq / amiga1 / dsgnrv13.lha / DesignerDemo / MultipleDemo / C / multipledemo.c < prev    next >
C/C++ Source or Header  |  1994-02-17  |  4KB  |  162 lines

  1. /* Compile me to get full executable. */
  2.  
  3. #include<multipledemoc.c>
  4.  
  5. int done=0;
  6. ULONG Class;
  7. ULONG count;
  8. UWORD Code;
  9. struct Gadget *Gad;
  10. struct IntuiMessage *imsg;
  11. struct MsgPort *MyMsgPort;
  12. struct WindowNode *WinNode;
  13. struct WindowNode *WinNode2;
  14. struct List WindowList;
  15.  
  16. int OpenNewWin(void)
  17. {
  18. struct WindowNode * WN;
  19. WN=AllocMem(sizeof(struct WindowNode),MEMF_CLEAR);
  20. if (WN !=NULL)
  21.     {
  22.     OpenWindowWinNodeWin( MyMsgPort, WN );
  23.     if (WN->Win==NULL)
  24.         {
  25.         FreeMem(WN,sizeof(struct WindowNode));
  26.         }
  27.     else
  28.         {
  29.         AddTail(&WindowList,WN);
  30.         WN->Win->UserData=(void *)WN;
  31.         count=0;
  32.         WinNode2=(struct WindowNode *)WindowList.lh_Head;
  33.         while (WinNode2->ln_Succ != NULL)
  34.             {
  35.             count++;
  36.             GT_SetGadgetAttrs(WinNode2->WinGadgets[2],WinNode2->Win, NULL, GTNM_Number, count, TAG_DONE);
  37.             WinNode2=WinNode2->ln_Succ;
  38.             }
  39.         return(0);
  40.         }
  41.     }
  42. return(1);
  43. }
  44.  
  45. void CloseOneWin( struct WindowNode * WN)
  46. {
  47.     Remove((struct Node *)WN);
  48.     CloseWindowWinNodeWin(WN);
  49.     FreeMem(WN,sizeof(struct WindowNode));
  50.     count=0;
  51.     WinNode2=(struct WindowNode *)WindowList.lh_Head;
  52.     while (WinNode2->ln_Succ != NULL)
  53.         {
  54.         count++;
  55.         GT_SetGadgetAttrs(WinNode2->WinGadgets[2],WinNode2->Win, NULL, GTNM_Number, count, TAG_DONE);
  56.         WinNode2=WinNode2->ln_Succ;
  57.         }
  58. }
  59.  
  60. void ProcessMenuIDCMPCommonMenu( UWORD MenuNumber)
  61. {
  62. UWORD MenuNum;
  63. UWORD ItemNumber;
  64. struct MenuItem *item;
  65. while ((MenuNumber != MENUNULL))
  66.     {
  67.     item = ItemAddress( CommonMenu, MenuNumber);
  68.     MenuNum = MENUNUM(MenuNumber);
  69.     ItemNumber = ITEMNUM(MenuNumber);
  70.     switch ( MenuNum )
  71.         {
  72.         case CommonMenu_Options :
  73.             switch ( ItemNumber )
  74.                 {
  75.                 case CommonMenu_Options_Item0 :
  76.                     WinNode=(struct WindowNode *)WindowList.lh_Head;
  77.                     while (WinNode->ln_Succ->ln_Succ != NULL)
  78.                         {
  79.                         CloseOneWin(WinNode);
  80.                         WinNode=(struct WindowNode *)WindowList.lh_Head;
  81.                         }
  82.                     break;
  83.                 case CommonMenu_Options_Item2 :
  84.                     WinNode=(struct WindowNode *)WindowList.lh_Head;
  85.                     while (WinNode->ln_Succ != NULL)
  86.                         {
  87.                         CloseOneWin(WinNode);
  88.                         WinNode=(struct WindowNode *)WindowList.lh_Head;
  89.                         }
  90.                     break;
  91.                 }
  92.             break;
  93.         }
  94.     MenuNumber = item->NextSelect;
  95.     }
  96. }
  97.  
  98. void main(void)
  99. {
  100. if (OpenLibs()==0)
  101.     {
  102.     NewList(&WindowList);
  103.     OpenDiskFonts();
  104.     if ((MyMsgPort=CreateMsgPort())!=0)
  105.         {
  106.         if (OpenNewWin()==0)
  107.             while(done==0)
  108.                 {
  109.                 Wait(1L << MyMsgPort->mp_SigBit);
  110.                 imsg=GT_GetIMsg(MyMsgPort);
  111.                 while (imsg != NULL )
  112.                     {
  113.                     Class=imsg->Class;
  114.                     Code=imsg->Code;
  115.                     Gad=(struct Gadget *)imsg->IAddress;
  116.                     WinNode = (struct WindowNode *)imsg->IDCMPWindow->UserData;
  117.                     GT_ReplyIMsg(imsg);
  118.                     switch ( Class )
  119.                         {
  120.                         case IDCMP_GADGETUP :
  121.                             switch ( Gad->GadgetID ) 
  122.                                 {
  123.                                 case CommonWin_Gad0 :
  124.                                     OpenNewWin();
  125.                                     break;
  126.                                 case CommonWin_Gad1 :
  127.                                     OpenNewWin();
  128.                                     OpenNewWin();
  129.                                     OpenNewWin();
  130.                                     OpenNewWin();
  131.                                     OpenNewWin();
  132.                                     break;
  133.                                 }
  134.                             break;
  135.                         case IDCMP_CLOSEWINDOW :
  136.                             CloseOneWin(WinNode);
  137.                             if (WindowList.lh_Head->ln_Succ==NULL)
  138.                               done=1;
  139.                             break;
  140.                         case IDCMP_MENUPICK :
  141.                             ProcessMenuIDCMPCommonMenu( Code );
  142.                             if (WindowList.lh_Head->ln_Succ==NULL)
  143.                               done=1;
  144.                             break;
  145.                         }
  146.                     imsg=GT_GetIMsg(MyMsgPort);
  147.                     }
  148.                 }
  149.         else
  150.             printf("Cannot open window.\n");
  151.         if (CommonMenu != NULL)
  152.           FreeMenus(CommonMenu);
  153.         DeleteMsgPort(MyMsgPort);
  154.         }
  155.     else
  156.         printf("Cannot make message Port.\n");
  157.     CloseLibs();
  158.     }
  159. else
  160.     printf("Cannot open libraries.\n");
  161. }
  162.